package com.ocn.li.scmdy.modules.app.service.impl;

import com.ocn.li.scmdy.common.utils.Constant;
import com.ocn.li.scmdy.common.utils.sms.SmsSingleSender;
import com.ocn.li.scmdy.common.utils.sms.SmsSingleSenderResult;
import com.ocn.li.scmdy.modules.app.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

/**
 * TODO 发送短信验证码实现类
 *
 * @author crazypenguin
 * @version 1.0.0
 * @createdate 2018/8/23
 */
@Service("smsService")
@Slf4j
public class SmsServiceImpl implements SmsService {

	@Override
	public boolean sendSms(String phone, int templId, ArrayList<String> params) {
		try {
			//初始化单发
			SmsSingleSender singleSender = new SmsSingleSender(Constant.SMS_APP_ID, Constant.SMS_APP_KEY);
			SmsSingleSenderResult singleSenderResult = singleSender. sendWithParam("86", phone, templId,
			params, Constant.SMS_APP_SIGNKEY, "", "");

            return singleSenderResult != null && singleSenderResult.result == 0;
		} catch (Exception e) {
			return false;
		}
	}

}
